package com.me.permission;

import java.util.Set;

/**
 * Mybatis 插件：数据权限帮助类
 *
 * @author ME
 */
public class PermissionHelper {

    private static final ThreadLocal<PermissionObj> LOCAL_PERMISSION = new ThreadLocal<>();

    /**
     * 设置 PermissionObj 参数
     *
     * @param permissionObj
     */
    public static void setLocalPermission(PermissionObj permissionObj) {
        LOCAL_PERMISSION.set(permissionObj);
    }

    /**
     * 获取 PermissionObj 参数
     *
     * @return
     */
    public static PermissionObj getLocalPermission() {
        return LOCAL_PERMISSION.get();
    }

    /**
     * 移除本地变量
     */
    public static void clearPermission() {
        LOCAL_PERMISSION.remove();
    }

    /**
     *
     * @param conditionClazz 需要校验数据权限的类
     * @param permissionList 数据权限列表
     */
    public static void setPermission(Class<?> conditionClazz, Set<String> permissionList) {
        PermissionObj permission = new PermissionObj(conditionClazz, permissionList);
        setLocalPermission(permission);
    }
}
